<template>
	<view class="page">
		<u-sticky>
			<view class="placeholder-bar" :style="{height: `${statusBarHeight}px`}"></view>
		</u-sticky>
		<u-sticky :offsetTop="statusBarHeight">
			<view class="top-bar">
				<view class="top-bar__l">
					<text>通知</text>
					<text class="icon-clear"></text>
				</view>
			</view>
		</u-sticky>
		<view class="items">
			<view class="item" v-for="(item, index) in items" :key="index" @click="goItem(index)">
				<view class="item-wrap" :style="{backgroundColor: `${item.bgColor}`}">
					<text class="item-icon" :class="item.icon"></text>
					<text class="item-badge" v-if="item.badge > 0">{{ item.badge }}</text>
				</view>
				<view class="item-label">{{ item.label }}</view>
			</view>
		</view>
		<z-paging ref="paging" fixed refresher-only class="paging" key="tab3"
			:style="{top: `${statusBarHeight + 44 + 112}px`, bottom: `${safeAreaBottom + 60}px`}" refresher-vibrate
			refresher-background="transparent" safe-area-inset-bottom @query="onRefresh" show-refresher-when-reload
			show-refresher-update-time refresher-update-time-key="tab3" @scroll="onScroll">
			<view class="content">
				<view class="chat-list">
					<u-swipe-action :autoClose="false">
						<u-swipe-action-item v-for="i in 10" :key="i" :index="i" :options="options" :disabled="disabled">
							<view class="cell" @click="goChat()">
								<view class="cell-icon">
									<u-avatar :size="52" src="/static/1.png"></u-avatar>
								</view>
								<view class="cell-content">
									<view class="cell-content__title">
										<view class="title-text">白兔</view>
										<view class="title-time">11:34</view>
									</view>
									<view class="cell-content__label">
										非常整洁，可以看到的美丽景色非常非非非非
									</view>
								</view>
							</view>
						</u-swipe-action-item>
					</u-swipe-action>
				</view>
			</view>
			<view class="placeholder-bar-bottom"></view>
		</z-paging>
	</view>
</template>

<script>
	import mixins from '@/mixins/index.js'
	export default {
		mixins: [mixins],
		data() {
			return {
				items: [{
						icon: 'icon-thumb-s',
						bgColor: 'rgba(255, 78, 77, .15)',
						badge: 1,
						label: '点赞'
					},
					{
						icon: 'icon-fans-s',
						bgColor: 'rgba(0, 188, 104, .15)',
						badge: 1,
						label: '粉丝'
					},
					{
						icon: 'icon-comment-s',
						bgColor: 'rgba(0, 109, 234, .15)',
						badge: 0,
						label: '评论'
					}
				],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#FF4E4D'
					}
				}],
				disabled: false
			}
		},
		created() {
			console.log('init tab3');
		},
		methods: {
			goItem(type) {
				uni.navigateTo({
					url: `/pages/common/interactive?type=${type}`
				})
			},
			goChat() {
				uni.navigateTo({
					url: '/pages/common/chat'
				})
			},
			onScroll() {
				this.timer && clearTimeout(this.timer)
				if (this.disabled == false) this.disabled = true
				this.timer = setTimeout(() => {
					this.disabled = false
					clearTimeout(this.timer)
				}, 300)
			}
		}
	}
</script>

<style scoped lang="scss">
	@import url('./common.scss');

	.page {
		background-color: #FFFFFF;
		padding: 0 22px;
	}

	.placeholder-bar {
		background-color: #FFFFFF;
	}

	.top-bar {

		&__l {
			display: flex;
			align-items: center;
			justify-content: flex-start;
			color: #232832 !important;

			text {
				display: block;
				font-size: 20px;
				line-height: 23px;
				font-weight: 500;
			}

			.icon-clear {
				margin-left: 10px;
				font-size: 14px;
			}
		}
	}

	.items {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 24px 0 14px;

		.item {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			width: 100%;
		}

		.item-wrap {
			position: relative;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 54px;
			height: 54px;
			border-radius: 15px;
		}

		.item-badge {
			position: absolute;
			top: 0;
			right: 0;
			transform: translate(50%, -50%);
			display: flex;
			align-items: center;
			justify-content: center;
			width: 18px;
			height: 18px;
			border-radius: 50%;
			background-color: #FF4E4D;
			color: #FFFFFF;
			font-size: 8px;
			line-height: 9px;
			font-weight: 400;
		}

		.icon-thumb-s {
			color: #FF4E4D;
		}

		.icon-fans-s {
			color: #00BC68;
		}

		.icon-comment-s {
			color: #006DEA;
		}

		.item-label {
			margin-top: 6px;
			color: #232832;
			font-size: 12px;
			line-height: 14px;
			font-weight: 400;
		}
	}

	.chat-list {
		padding: 0 22px;
	}

	.cell {
		display: flex;
		align-items: center;
		padding: 10px 0;
		background-color: #FFFFFF;

		.cell-icon {
			flex: 0 0 52px;
			height: 52px;
			border-radius: 50%;
		}

		.cell-content {
			width: 100%;
			margin-left: 15px;
			overflow: hidden;

			&__title {
				display: flex;
				align-items: center;
				margin-right: 10px;
			}

			.title-text {
				flex: 1;
				padding-right: 10px;
				color: #232832;
				font-size: 15px;
				line-height: 18px;
				font-weight: 500;
			}

			.title-time {
				color: #787B86;
				font-size: 12px;
				line-height: 14px;
				font-weight: 400;
			}

			&__label {
				width: 100%;
				margin-top: 8px;
				color: #787B86;
				font-size: 15px;
				line-height: 18px;
				font-weight: 400;
				white-space: nowrap;
				text-overflow: ellipsis;
				overflow: hidden;
			}
		}
	}
</style>